package com.oracle.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.oracle.common.TemplateMoudleMethod;
import com.oracle.moudle.TemplateMoudleimp;
import com.oracle.service.FeignGetBoyService;
import com.oracle.service.FeignGetGirlService;
import com.oracle.service.IGirlService;
import com.oracle.vo.Boy;
import com.oracle.vo.Girl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;


import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @program: CampusMatching
 * @description:
 * @author: zhaolei
 * @create: 2020-07-25 11:01
 **/
@Controller
@RequestMapping("/Girl")
public class SourceHandler implements FeignGetGirlService {

    @Autowired
    RestTemplate restTemplate;

    @Autowired
    DiscoveryClient discoveryClient;

    @Autowired
    IGirlService iGirlService;

    @Autowired
    FeignGetBoyService feignGetBoyService;

    @GetMapping("/index")
    public String getPage(){
        System.out.println("进入女士入口");
        return "Main";
    }


    @PostMapping("/getBoy")
    public  String getGirl(Girl girl, Map<String,Object> map){
        System.out.println(girl.toString());
       List list=feignGetBoyService.getBoy(girl);
        System.out.println(list.toString());
        map.put("blist",list);
        return "resboy";

    }

    //被调用的服务
    @Override
    @HystrixCommand(fallbackMethod = "get_fallback")
    @PostMapping("/getGirl")
    @ResponseBody
    public List getGirl(@RequestBody Boy boy){
        System.out.println("映射成功！");
        System.out.println(boy.toString());
        TemplateMoudleMethod templateMoudleMethod=new TemplateMoudleimp(boy);
        List<Object> list =templateMoudleMethod.run();
//        Girl girl=iGirlService.getGirlByHobby(boy.getBhobby());
        System.out.println("list:" +list);
        return list;
    }


    //熔断
    public List get_fallback(Boy boy){
        List list=new ArrayList();
        System.out.println("熔断开启");
        Girl girl=new Girl();
        girl.setGname("熔断");
        return list;
    }

}
